const fs = require("fs");
const path = require("path");

const gitHookPath = path.resolve("../../.git/hooks");

new Promise((resolve) => {
    fs.mkdir(gitHookPath, { recursive: true }, (err) => {
        if (err) {
            throw err;
        }
        resolve();
    });
}).then(() => {
    const shell =`#!/usr/bin/env bash\n` +
        `export PATH=/usr/local/bin:$PATH\n` +
        `node "${ path.resolve(__dirname, "pre-push.js") }"`;
    fs.writeFile(path.resolve(gitHookPath, "pre-push"), shell, (error) => {
        if (error) {
            console.log(error);
        }
    });
});
